<?php
namespace app\admin\controller;

//分类页
use app\admin\logic\GcategoryLogic;
use app\admin\logic\GoodsLogic;
use app\BaseController;
use think\facade\Request;
use think\facade\View;

class Gcategory extends BaseController {
    public function cate(){
        //拼装查询条件 判断当前parent_id 应该是多少 方法返回的where
        $where=GcategoryLogic::reformData();
        //查询所有的一级分类  上面的where赋值进去
        $cate=\app\admin\model\Gcategory::cateList($where);
        //查询分类下是否有下一级,有下一级赋值cate_name
        $cate=GcategoryLogic::setCateNext($cate);
       View::assign('cate',$cate);
        $fenlei=GoodsLogic::goodCate();
        View::assign('fenlei',$fenlei);
        return View::fetch();
    }


    //分类页修改
    public function cateedit(){
        if (Request::isPost()){
            $post=Request::post();
            $data=GcategoryLogic::cateEditInfo($post);
            $res=\app\admin\model\Gcategory::getCateEdit($data,[]);
            if ($res){
                $this->success('修改成功',url('cate'));
            }else{
                $this->error('修改失败');
            }


        }else{
            //分类
            $fenlei=GoodsLogic::goodCate();
            View::assign('fenlei',$fenlei);
            $get=Request::get();
            $find=\app\admin\model\Gcategory::getCateEdit([],$get);
            View::assign('find',$find);
            return View::fetch();
        }

    }

    //分类页添加
     public function cateAddInfo(){
        if (Request::post()){
            $post=Request::post();
            $data=GcategoryLogic::cateAddInfo($post);
            $res=\app\admin\model\Gcategory::getCateAdd($data);
            if ($res){
                $this->success('添加成功',url('cate'));
            }else{
                $this->error('添加失败');
            }

        }else{

            return View::fetch();
        }


      }


}